package com.Day6;

import java.util.HashSet;
import java.util.Set;

public class P2 {
    public int[] intersection(int[] num1, int[] num2){
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        //set化
        for (int num : num1){
            set1.add(num);
        }

        for (int num : num2){
            if (set1.contains(num)){
                set2.add(num);
            }
        }

        int[] intersection = new int[set2.size()];
        int index = 0;
        for (int num :set2){
            intersection[index++] = num;
        }
        return intersection;
    }
    }

